package com.shanghaionstar.nav.manager;

import android.support.v4.app.FragmentActivity;

import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.UiSettings;
import com.amap.api.services.core.ServiceSettings;
import com.onstar.cn.common.util.DeviceUtil;
import com.onstar.cn.map.MapContainer;
import com.onstar.cn.map.MapContainerImpl;
import com.onstar.cn.map.OMapActivity;

/**
 * Created by Rengui Lu on 2016/7/12.
 */
public abstract class BaseHandler implements IHandlerManager{
    protected FragmentActivity mActivity;
    protected AMap mMapView;

    public MapContainer getmMapContainer() {
        return mMapContainer;
    }

    public void setmMapContainer(MapContainer mMapContainer) {
        this.mMapContainer = mMapContainer;
    }

    protected MapContainer mMapContainer;

    public BaseHandler(OMapActivity oMapActivtiy, AMap mapView) {
        this.mActivity=oMapActivtiy;
        this.mMapView = mapView;
        UiSettings setting = this.mMapView.getUiSettings();
        setting.setZoomControlsEnabled(false);
        mMapContainer = new MapContainerImpl(oMapActivtiy, this.mMapView, null);
        setLanguage(mapView);
        init();
    }

    public void setTraffic(boolean isOpen) {
        mMapView.setTrafficEnabled(isOpen);
        mMapView.invalidate();
    }

    public abstract void init();

    private void setLanguage(AMap mapView) {
        if (DeviceUtil.isChineseLanguage()) {
            mapView.setMapLanguage(AMap.CHINESE);
            ServiceSettings.getInstance().setLanguage(ServiceSettings.CHINESE);
        } else {
            mapView.setMapLanguage(AMap.ENGLISH);
            ServiceSettings.getInstance().setLanguage(ServiceSettings.ENGLISH);
        }
    }

}
